<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
	</head>
	<body>
		请输入年份：<input type="number" id="year">
		<br>
		请输入月份：<input type="number" id="month">
		<br>
		请输入日期：<input type="number" id="day"> 
		<br>
		<button id="judge">判断</button>
	</body>
</html>
<script>
	//获取元素
	//获取年份输入框
	var yearInput = document.getElementById("year");
	//获取月份输入框
	var monthInput = document.getElementById("month");
	//获取日期输入框
	var dayInput = document.getElementById("day");
	//判断按钮
	var judgeBtn = document.getElementById("judge");
     
     //1 3 5 7 8 10 12
	var jan = mar = may = jul = aug = oct = dec = 31;
	// 4 6 9 11 
	var apr = jun = sep = nov = 30;
	// 2
	var feb = 28;

	//按钮点击事件
	judgeBtn.onclick = function() {
		//获取年
		var year = yearInput.value;
		//月
		var month = monthInput.value;
		var day = dayInput.value;

        //判断是不是闰年
        var r = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;

        // fed += r ? 1 : 0;
        if (r) feb += 1;

        //把month转化成number类型，因为输入框里的是string类型
        day = day - 0;
        month = month - 0;

        var wd = 0;
        switch (month) {
        	//case语句比较值使用的 === ，既比较类型又比较值
        	case 1:
        	     wd = day;
        	     break;
        	case 2:
        	     wd = jan + day;
        	     break;
        	case 3:
                 wd = jan + feb + day;
                 break;
            case 4: 
                 wd = jan + feb + mar + day;
                 break;
            case 5:
                 wd = jan + feb + mar + apr + day;
                 break;
            case 6:
                  wd = jan + feb + mar + apr + may + day;
                  break;
            case 7:
                  wd = jan + feb + mar + apr + may + jun + day;
                  break;
            case 8:
                  wd = jan + feb + mar + apr + may + jun + jul + day;  
                  break;
            case 9:
                  wd = jan + feb + mar + apr + may + jun + jul + aug + day;
                  break;
            case 10:
                   wd = jan + feb + mar + apr + may + jun + jul + aug + sep + day;
                   break;
             case 11:
                   wd = jan + feb + mar + apr + may + jun + jul + aug + sep + oct + day; 
                   break;
             case 12:
                   wd = jan + feb + mar + apr + may + jun + jul + aug + sep + nov + day; 
                   break;
                 default:
                   break;

        }


        alert("该天是一年第" + wd + "天");


 




	};





</script>